package com.seele.tigerwallet.async;

import com.seele.tigerwallet.model.MarketModel;
import com.seele.tigerwallet.ui.callback.DaoTaskListener;
import com.seele.tigerwallet.ui.manager.DaoManager;

import java.util.List;

public class DaoTask extends SimpleTask<Integer> {


    private List<Integer> mIntegerList;
    private List<MarketModel> mMarketModelList;

    private DaoTaskListener mListener;


    public void setDaoTaskListener(DaoTaskListener listener) {
        this.mListener = listener;
    }

    public DaoTask(List<Integer> mIntegerList, List<MarketModel> mModels) {
        this.mIntegerList = mIntegerList;
        this.mMarketModelList = mModels;
    }

    @Override
    protected Integer doInBackground() {
        int index = 0;
        try {
            if (null != mMarketModelList && mMarketModelList.size() > 0) {
                for (MarketModel marketModel : mMarketModelList) {
                    if (!mIntegerList.contains(marketModel.id)) {
                        index = DaoManager.getMarketDao().delete(marketModel);
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return index;
    }

    @Override
    protected void onPostExecute(Integer result) {
        if (null != mListener) {
            mListener.onResponse();

        }


    }

}
